<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<%@include file="/common/head.jsp" %>

<c:set var="module" value="order"/>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                    	<form role="form" class="form-inline" id="query-form" method="post" action="${ctx }/admin/order/list" >
                    		<!-- 查询开始 -->
                            <div class="form-group">
                                <label for="query-orderNo" class="sr-only">订单编号</label>
                                	<input type="text" placeholder="订单编号" id="query-orderNo" name="orderNo" value="${query.orderNo }" class="form-control">
                            </div>
                            
                            <div class="form-group">
                                <label for="query-user" class="sr-only">购买用户</label>
                                	<input type="hidden"  id="user-id" name="user.id" value="${query.user.id }" class="form-control">
				                 	<input type="text" placeholder="购买用户" class="form-control" id="username" name="user.username" value="${query.user.username }" 
				                 		onclick="bring({
										                 	url:'${ctx}/admin/user/list',
										                 	name: 'username',
										                 	idInput: 'user-id',
										                 	nameInput: 'username'
										                 	})" />
                            </div>
                            <%-- 
                            <div class="form-group">
                                <label for="query-operatorUser" class="sr-only">运营商</label>
                                	<input type="text" placeholder="运营商" id="query-operatorUser" name="operatorUser" value="${query.operatorUser }" class="form-control">
                            </div>
                            <div class="form-group">
                                <label for="query-factoryUser" class="sr-only">工厂</label>
                                	<input type="text" placeholder="工厂" id="query-factoryUser" name="factoryUser" value="${query.factoryUser }" class="form-control">
                                	<input type="hidden"  id="query-factoryUser-id" name="factoryUser.id" value="${query.factoryUser.id }" class="form-control">
				                 	<input type="text" placeholder="工厂" class="form-control" id="query-factoryUser-name" name="factoryUser.name" value="${query.factoryUser.username }" 
				                 		onclick="bring({
										                 	url:'${ctx}/admin/user/list',
										                 	name: 'username',
										                 	idInput: 'query-factoryUser-id',
										                 	nameInput: 'query-factoryUser-name'
										                 	})" />
                            </div>
                            <div class="form-group">
                                <label for="query-payStatus" class="sr-only">支付状态</label>
                                	<input type="text" placeholder="支付状态" id="query-payStatus" name="payStatus" value="${query.payStatus }" class="form-control">
                                	<select name="payStatus" class="form-control">
                                		<option value="">请选择支付状态</option>	
	                                	<c:forEach items="${pss }" var="ts">
	    		                            <option value="${ts.value }" <c:if test="${ts.value eq query.status }">selected="selected"</c:if>>${ts.remark }</option>
	                                	</c:forEach>
                                	</select>
                            </div>
                            <div class="form-group">
                                <label for="query-status" class="sr-only">状态</label>
                                	<input type="text" placeholder="状态" id="query-status" name="status" value="${query.status }" class="form-control">
                                	<select name="status" class="form-control">
                                		<option value="">请选择状态</option>	
	                                	<c:forEach items="${oss }" var="ss">
	    		                            <option value="${ss.value }" <c:if test="${ss.value eq query.status }">selected="selected"</c:if>>${ss.remark }</option>
	                                	</c:forEach>
                                	</select>
                            </div>
                            <div class="form-group">
                                <label for="query-payType" class="sr-only">支付方式</label>
                                	<input type="text" placeholder="支付方式" id="query-payType" name="payType" value="${query.payType }" class="form-control">
                                	<select name="payType" class="form-control">
                                		<option value="">请选择支付方式</option>	
	                                	<c:forEach items="${pts }" var="ts">
	    		                            <option value="${ts.value }" <c:if test="${ts.value eq query.payType }">selected="selected"</c:if>>${ts.remark }</option>
	                                	</c:forEach>
                                	</select> 
                            </div>
                            <div class="form-group">
                                <label for="query-receiveName" class="sr-only">收件人</label>
                                	<input type="text" placeholder="收件人" id="query-receiveName" name="receiveName" value="${query.receiveName }" class="form-control">
                            </div>
                            <div class="form-group">
                                <label for="query-receiveMobile" class="sr-only">收件人电话</label>
                                	<input type="text" placeholder="收件人电话" id="query-receiveMobile" name="receiveMobile" value="${query.receiveMobile }" class="form-control">
                            </div>
                            <div class="form-group">
                                <label for="query-expressCompany" class="sr-only">物流公司</label>
                                	<input type="text" placeholder="物流公司" id="query-expressCompany" name="expressCompany" value="${query.expressCompany }" class="form-control">
                            </div>
                             --%>
                            <div class="form-group">
                                <label for="query-expressNo" class="sr-only">物流单号</label>
                                	<input type="text" placeholder="物流单号" id="query-expressNo" name="expressNo" value="${query.expressNo }" class="form-control">
                            </div>
                            <div class="form-group">
                            	<button class="btn btn-primary form-control" type="submit"><i class="fa fa-check"></i>&nbsp;查询</button>
                            </div>
                        </form>
                    
						<div>
							<p>
								<%-- 
		                        <button type="button" class="btn btn-outline btn-primary" onclick="add()">新增</button>
		                         --%>
		                        
		                        
		                        <button type="button" class="btn btn-outline btn-info" onclick="edit()">详情</button>
		                        
		                        
		                        <%-- 
		                        <button type="button" class="btn btn-outline btn-danger" onclick="del();">删除</button>
		                         --%>
		                    </p>
						</div>
						<table id="table" data-toggle="table" data-height="400" data-click-to-select="true" data-mobile-responsive="true">
                                    <thead>
                                        <tr>
                                            <th data-field="state" data-checkbox="true"></th>
                                            <th data-field="id">id</th>
                                            <th data-field="orderNo">订单编号</th>
                                            <th data-field="user">购买用户</th>
                                            <!-- <th data-field="operatorUser">运营商</th>
                                            <th data-field="factoryUser">工厂</th> -->
                                            <th data-field="createTime">下单时间</th>
                                          <!--   <th data-field="payTime">支付时间</th>
                                            <th data-field="deliverTime">发货时间</th> -->
                                            <th data-field="amount">订单总额</th>
                                           <!--  <th data-field="actualPayAmount">实付金额</th> -->
                                            <th data-field="payStatus">支付状态</th>
                                            <th data-field="status">发货状态</th>
                                            <th data-field="payType">支付方式</th>
                                            <th data-field="expressCompany">物流公司</th>
                                             <th data-field="expressNo">物流编号</th>
                                            <th></th>
                                           <!--  <th data-field="receiveName">收件人</th>
                                            <th data-field="receiveMobile">收件人电话</th>
                                            <th data-field="zipcode">邮编</th>
                                            <th data-field="province">省</th>
                                            <th data-field="city">市</th>
                                            <th data-field="district">地区</th>
                                            <th data-field="address">详细地址</th>
                                            <th data-field="expressCompany">物流公司</th>
                                            <th data-field="expressNo">物流单号</th>
                                            <th data-field="operatorRemark">运营商备注</th>
                                            <th data-field="factoryRemark">工厂备注</th>
                                            <th data-field="invoiceType">发票类型</th>
                                            <th data-field="invoiceTitle">发票抬头</th> -->
                                        </tr>
                                    </thead>
							<tbody>
								<c:forEach items="${list }" var="n" varStatus="idx">
								<tr data-index="${idx.index }">
									<td class="bs-checkbox">
										<input data-index="0" name="btSelectItem" type="checkbox">
									</td>
									<td style="">${n.id }</td>
									<td style="">${n.orderNo }</td>
									<td style="">${n.user.username}</td>
									<%-- <td style="">${n.operatorUser.username}</td>
									<td style="">${n.factoryUser.username}</td> --%>
									<td style="">
										<fmt:formatDate value="${n.createTime }" pattern="yyyy-MM-dd"/>
									</td>
									<%-- <td style="">
										<fmt:formatDate value="${n.payTime }" pattern="yyyy-MM-dd HH:mm:ss"/>
									</td>
									<td style="">
										<fmt:formatDate value="${n.deliverTime }" pattern="yyyy-MM-dd HH:mm:ss"/>
									</td> --%>
									<td style="">${n.amount }</td>
									<%-- <td style="">${n.actualPayAmount }</td> --%>
									<td style="">${enum:list('PayStatus', n.payStatus) }</td>
									<td style="">${enum:list('OrderStatus', n.status) }</td>
									<td style="">${enum:list('PayType', n.payType) }</td>
									<td style="">${n.expressCompany }</td>
									<td style="">${n.expressNo }</td>
									<td>
										<a href="javascript:void(0);" onclick="showItems('${n.id}')">详情</a>
										<a href="${ctx }/admin/order/downExcel?id=${n.id}" onclick="">导出</a>
									</td>
									<%-- <td style="">${n.receiveName }</td>
									<td style="">${n.receiveMobile }</td>
									<td style="">${n.zipcode }</td>
									<td style="">${n.province.name}</td>
									<td style="">${n.city.name}</td>
									<td style="">${n.district.name}</td>
									<td style="">${n.address }</td>
									<td style="">${n.expressCompany }</td>
									<td style="">${n.expressNo }</td>
									<td style="">${n.operatorRemark }</td>
									<td style="">${n.factoryRemark }</td>
									<td style="">${n.invoiceType }</td>
									<td style="">${n.invoiceTitle }</td> --%>
								</tr>
								</c:forEach>
							</tbody>
						</table>
                   
						<div class="row">
							<div class="col-sm-6">
								<div class="dataTables_info" id="DataTables_Table_0_info"
									role="alert" aria-live="polite" aria-relevant="all">显示第 ${(page.page - 1) * page.pageSize  + 1}
									到第 ${(page.page) * page.pageSize} 项，共 ${page.totalRecords } 项</div>
							</div>
							<div class="col-sm-6">
								<div class="dataTables_paginate paging_simple_numbers"
									id="DataTables_Table_0_paginate">
									<ul class="pagination" id="pagination">
									</ul>
								</div>
							</div>
						</div>

					</div>
                </div>
            </div>
        </div>
    </div>

<%@include file="/common/foot.jsp" %>
<script>
function add() {
		layer.open({
		    type: 2,
		    skin: 'layui-layer-rim', //加上边框
		    area: [layer_default_width, layer_default_height], //宽高
		    content: "${ctx}/admin/order/detail",
		    btn: ['确定', '取消'],
		    yes: function(index, layero){ //或者使用btn1
		    	var detailForm = layer.getChildFrame('form', index);
		    	console.log(detailForm);
		    	detailForm.ajaxSubmit({
		    		success: function(data) {
		    			if (isSuccess(data)) {
		    				layer.close(index);
		    				reload();
		    			} else {
		    			}
		    		}
		    	});
		    }, cancel: function(index){ //或者使用btn2
		        //按钮【按钮二】的回调
		    }
		});
}

function showItems(orderId) {
	layer.open({
	    type: 2,
	    skin: 'layui-layer-rim', //加上边框
	    area: [layer_default_width, layer_default_height], //宽高
	    content: "${ctx}/admin/orderItem/list?order.id=" + orderId,
	    btn: ['确定', '取消'],
	    yes: function(index, layero){ //或者使用btn1
	    	var detailForm = layer.getChildFrame('form', index);
	    	console.log(detailForm);
	    	detailForm.ajaxSubmit({
	    		success: function(data) {
	    			if (isSuccess(data)) {
	    				layer.close(index);
	    				reload();
	    			} else {
	    			}
	    		}
	    	});
	    }, cancel: function(index){ //或者使用btn2
	        //按钮【按钮二】的回调
	    }
	});	
}

function edit() {
	var selections = $('#table').bootstrapTable('getAllSelections');
	if (selections.length == 0) {
		error('请选择一条记录');
		return;
	} else if (selections.length > 1) {
		error('只能选择一条记录');
		return;
	}
	var id = selections[0].id;
	
	layer.open({
	    type: 2,
	    skin: 'layui-layer-rim', //加上边框
	    area: [layer_default_width, layer_default_height], //宽高
	    content: "${ctx}/admin/order/detail?id=" + id,
	    btn: ['确定', '取消'],
	    yes: function(index, layero){ //或者使用btn1
	    	var detailForm = layer.getChildFrame('form', index);
	    	console.log(detailForm);
	    	detailForm.ajaxSubmit({
	    		success: function(data) {
	    			if (isSuccess(data)) {
	    				layer.close(index);
	    				reload();
	    			} else {
	    			}
	    		}
	    	});
	    }, cancel: function(index){ //或者使用btn2
	        //按钮【按钮二】的回调
	    }
	});
}
var page = "${page.page}";
function reload() {
	page_submit(page);
}
function del() {
	var selections = $('#table').bootstrapTable('getAllSelections');
	if (selections.length < 1) {
		error('请选择要删除的记录');
		return;
	}
	layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
		var ids = new Array();
		for (var i = 0; i < selections.length; i++) {
			ids.push(selections[i].id);
		}
		$.ajax({
			url: "${ctx}/admin/order/delete",
			data: {
				ids: ids.join(',')
			},
			success: function(data) {
				if (isSuccess(data)) {
					layer.close(index);
					reload();
				}
			}
		});
	});
	
}
paging('pagination', ${page.totalPages}, ${page.page});

</script>
</body>
</html>